package com.cdh.oa.interceptor;

import com.cdh.oa.util.ConstUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;

@Component
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("拦截器地址："+request.getRequestURI());
        Object obj = request.getSession().getAttribute(ConstUtil.CURRENT_USER);
        if(Objects.nonNull(obj)){
            return true;
        }
        response.sendRedirect("/");
        return false;
    }
}
